<?php

class TemplateLoader extends TraitOwner
{
	public function __construct( )
	{
		$this->Module = 'Sandbox';
		$this->Traits[] = new PHPXLoadableTrait( ); // this makes the class able to instantiate from a phpx file
		$this->InitTraits( ); // activates the traits
		$this->InitPHPX( ); // activates the PHPXLoadableTrait
		$this->Template = '';
	}
	
	public function Init( )
	{
		// @this function needs to be in place for the PHPX to create the component
		// it should function like the constructor of a 'normal' class
	}
	
	// this function is called from the Router when encountering a phpx file
	public function Render( )
	{
		$Path = $this->GetTemplatePath( );
		if(file_exists($Path))
			require $this->GetTemplatePath( );
		else
			throw new Exception($Path . ' does not exists!');
	}
	
	public function GetText( )
	{
		ob_start();
		$this->Render();
		$Text = ob_get_clean( );
		return $Text;
	}
}